module App::Controller
    class WatchdogObserver < Qt::Object
        slots 'screen_saver_activated(QObject*)'
        slots 'screen_saver_deactivated(QObject*, QDateTime*)'

        def initialize(watchdog)
            super()

            Qt::Object.connect(watchdog, SIGNAL('screenSaverActivated(QObject*)'),
                self, SLOT('screen_saver_activated(QObject*)'))
            Qt::Object.connect(watchdog, SIGNAL('screenSaverDeactivated(QObject*, QDateTime*)'),
                self, SLOT('screen_saver_deactivated(QObject*, QDateTime*)'))
        end

        private
        def screen_saver_activated(running_task)
            running_task.stop
        end

        def screen_saver_deactivated(last_running_task, idle_from)
            dialog = App::View::ScreenSaverDeactivated.new($widget.view, idle_from)
            ret = dialog.exec
            begin
                last_running_task.start if ret == dialog.class.Ok
            rescue CommunicationError
                App::View::ErrorDialog.new $widget.view, $!
                exit 0
            end
        end
    end
end
